package cn.edu.scau.cmi.wujiaxian.exercise10;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Example10_13 {
	
	//对象流（直接存储一个对象）
	public static void main(String[] args) {
		TV changhong = new TV();
		changhong.setName("长虹电视");
		changhong.setPrice(5678);
		File file = new File("television.txt");
		
		try {
			FileOutputStream fos = new FileOutputStream(file);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(changhong);
			oos.close();
			FileInputStream fis = new FileInputStream(file);
			ObjectInputStream ois = new ObjectInputStream(fis);
			TV xinfei = (TV) ois.readObject();
			ois.close();
			System.out.println(xinfei.getName() + xinfei.getPrice() + xinfei.getClass());
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	
}
